﻿using Microsoft.AspNetCore.Mvc;
using Open.Core.Extension.Results;

namespace Open.Core.Extension
{
    public abstract class OpenApiController : ControllerBase
    {
        protected OpenApiController()
        {

        }

        /// <summary>
        /// 返回成功消息
        /// </summary>
        /// <param name="data">数据</param>
        /// <param name="message">消息</param>
        protected virtual IActionResult Success(dynamic data = null, string message = null)
        {
            message ??= "成功";
            return new Result(StateCode.Ok, message, data);
        }

        /// <summary>
        /// 成功
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="byteStr"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        protected virtual IActionResult Success<T>(object byteStr, string message = null)
        {

            return Success(byteStr, message);
        }

        /// <summary>
        /// 返回失败消息
        /// </summary>
        /// <param name="message">消息</param>
        protected virtual IActionResult Fail(string message)
        {
            return new Result(StateCode.Fail, message);
        }
    }
}